<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Guava,缓存," />










<meta name="description" content="使用Guava库来实现JVM缓存，通过2种不同的方式实现，并测试提供的缓存失效、缓存定时刷新、缓存删除监听功能">
<meta name="keywords" content="Guava,缓存">
<meta property="og:type" content="article">
<meta property="og:title" content="使用Guava实现缓存">
<meta property="og:url" content="http://yoursite.com/2018/12/05/使用Guava实现缓存/使用Guava实现缓存/index.html">
<meta property="og:site_name" content="程序员乌托邦">
<meta property="og:description" content="使用Guava库来实现JVM缓存，通过2种不同的方式实现，并测试提供的缓存失效、缓存定时刷新、缓存删除监听功能">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2018-12-05T01:32:47.661Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="使用Guava实现缓存">
<meta name="twitter:description" content="使用Guava库来实现JVM缓存，通过2种不同的方式实现，并测试提供的缓存失效、缓存定时刷新、缓存删除监听功能">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2018/12/05/使用Guava实现缓存/使用Guava实现缓存/"/>





  <title>使用Guava实现缓存 | 程序员乌托邦</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">程序员乌托邦</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2018/12/05/使用Guava实现缓存/使用Guava实现缓存/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Wolf、Heart">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="程序员乌托邦">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">使用Guava实现缓存</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-12-05T09:22:57+08:00">
                2018-12-05
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Guava/" itemprop="url" rel="index">
                    <span itemprop="name">Guava</span>
                  </a>
                </span>

                
                
                  ， 
                
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/缓存/" itemprop="url" rel="index">
                    <span itemprop="name">缓存</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h3 id="使用Guava库来实现JVM缓存，通过2种不同的方式实现，并测试提供的缓存失效、缓存定时刷新、缓存删除监听功能"><a href="#使用Guava库来实现JVM缓存，通过2种不同的方式实现，并测试提供的缓存失效、缓存定时刷新、缓存删除监听功能" class="headerlink" title="使用Guava库来实现JVM缓存，通过2种不同的方式实现，并测试提供的缓存失效、缓存定时刷新、缓存删除监听功能"></a>使用Guava库来实现JVM缓存，通过2种不同的方式实现，并测试提供的缓存失效、缓存定时刷新、缓存删除监听功能</h3><a id="more"></a>
<h1 id="方式一：LoadingCache"><a href="#方式一：LoadingCache" class="headerlink" title="方式一：LoadingCache"></a>方式一：LoadingCache</h1><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">public class GuavaCacheTest1 &#123;</span><br><span class="line"></span><br><span class="line">    public static void main(String[] args) throws ExecutionException, InterruptedException &#123;</span><br><span class="line">        /**</span><br><span class="line">         * 定义缓存，写入10s失效</span><br><span class="line">         */</span><br><span class="line">        LoadingCache&lt;String, Student&gt; loadingCache = CacheBuilder.newBuilder()</span><br><span class="line">                .maximumSize(1000)</span><br><span class="line">                .expireAfterWrite(10, TimeUnit.SECONDS)</span><br><span class="line">                .build(new CacheLoader&lt;String, Student&gt;() &#123;</span><br><span class="line">                    @Override</span><br><span class="line">                    public Student load(String key) throws Exception &#123;</span><br><span class="line">                        Student student = Student.builder()</span><br><span class="line">                                .id(10001)</span><br><span class="line">                                .name(&quot;guava loading cache&quot;)</span><br><span class="line">                                .build();</span><br><span class="line">                        System.out.println(&quot;【加载数据并放入缓存，缓存key】:&quot; + key);</span><br><span class="line">                        return student;</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        while (true) &#123;</span><br><span class="line">            System.out.println(loadingCache.get(&quot;student-loading-cache&quot;));</span><br><span class="line">            Thread.sleep(1000);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h1 id="方式二：LocalManualCache"><a href="#方式二：LocalManualCache" class="headerlink" title="方式二：LocalManualCache"></a>方式二：LocalManualCache</h1><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">public class GuavaCacheTest2 &#123;</span><br><span class="line"></span><br><span class="line">    public static void main(String[] args) throws ExecutionException, InterruptedException &#123;</span><br><span class="line">        Cache&lt;String, Student&gt; cache = CacheBuilder.newBuilder()</span><br><span class="line">                .maximumSize(1000)</span><br><span class="line">                .expireAfterWrite(10, TimeUnit.SECONDS)</span><br><span class="line">                .build();</span><br><span class="line"></span><br><span class="line">        while (true) &#123;</span><br><span class="line">            Student student = cache.get(&quot;student-callable-cache&quot;, () -&gt; &#123;</span><br><span class="line">                System.out.println(&quot;【加载数据并放入缓存，缓存key】:student-callable-cache&quot;);</span><br><span class="line">                return Student.builder()</span><br><span class="line">                        .id(10002)</span><br><span class="line">                        .name(&quot;guava callable cache&quot;)</span><br><span class="line">                        .build();</span><br><span class="line">            &#125;);</span><br><span class="line"></span><br><span class="line">            System.out.println(student);</span><br><span class="line">            Thread.sleep(1000);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h1 id="方式三：测试maximumSize含义"><a href="#方式三：测试maximumSize含义" class="headerlink" title="方式三：测试maximumSize含义"></a>方式三：测试maximumSize含义</h1><p>示例代码中指定存储的元素个数为2，当存储超过2个元素的时候，会删除元素并触发监听器，可以知道哪些元素被删除掉<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><span class="line">public class GuavaCacheTest3 &#123;</span><br><span class="line"></span><br><span class="line">    public static void main(String[] args) throws ExecutionException, InterruptedException &#123;</span><br><span class="line">        /**</span><br><span class="line">         * maximumSize指定缓存元素的个数，本示例指定2个，如果超过2个，就会触发删除监听事件</span><br><span class="line">         */</span><br><span class="line">        Cache&lt;String, Student&gt; cache = CacheBuilder.newBuilder()</span><br><span class="line">                .maximumSize(2)</span><br><span class="line">                .expireAfterWrite(10, TimeUnit.SECONDS)</span><br><span class="line">                .removalListener(new RemovalListener&lt;Object, Object&gt;() &#123;</span><br><span class="line">                    @Override</span><br><span class="line">                    public void onRemoval(RemovalNotification&lt;Object, Object&gt; notification) &#123;</span><br><span class="line">                        System.out.println(&quot;【key】:&quot; + notification.getKey() + &quot;被移除&quot;);</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;)</span><br><span class="line">                .build();</span><br><span class="line"></span><br><span class="line">        cache.get(&quot;student-callable-cache1&quot;, () -&gt; &#123;</span><br><span class="line">            System.out.println(&quot;【加载数据并放入缓存，缓存key】:student-callable-cache1&quot;);</span><br><span class="line">            return Student.builder()</span><br><span class="line">                    .id(10002)</span><br><span class="line">                    .name(&quot;guava callable cache1&quot;)</span><br><span class="line">                    .build();</span><br><span class="line">        &#125;);</span><br><span class="line"></span><br><span class="line">        cache.get(&quot;student-callable-cache2&quot;, () -&gt; &#123;</span><br><span class="line">            System.out.println(&quot;【加载数据并放入缓存，缓存key】:student-callable-cache2&quot;);</span><br><span class="line">            return Student.builder()</span><br><span class="line">                    .id(10003)</span><br><span class="line">                    .name(&quot;guava callable cache2&quot;)</span><br><span class="line">                    .build();</span><br><span class="line">        &#125;);</span><br><span class="line"></span><br><span class="line">        cache.get(&quot;student-callable-cache3&quot;, () -&gt; &#123;</span><br><span class="line">            System.out.println(&quot;【加载数据并放入缓存，缓存key】:student-callable-cache3&quot;);</span><br><span class="line">            return Student.builder()</span><br><span class="line">                    .id(10004)</span><br><span class="line">                    .name(&quot;guava callable cache3&quot;)</span><br><span class="line">                    .build();</span><br><span class="line">        &#125;);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h1 id="方式四：刷新缓存"><a href="#方式四：刷新缓存" class="headerlink" title="方式四：刷新缓存"></a>方式四：刷新缓存</h1><p>示例代码中指定写入缓存10s后缓存失效，并且指定每5s进行一次缓存刷新<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line">public class GuavaCacheTest4 &#123;</span><br><span class="line"></span><br><span class="line">    public static void main(String[] args) throws ExecutionException, InterruptedException &#123;</span><br><span class="line">        /**</span><br><span class="line">         * 定义缓存，写入10s失效</span><br><span class="line">         */</span><br><span class="line">        LoadingCache&lt;String, Student&gt; loadingCache = CacheBuilder.newBuilder()</span><br><span class="line">                .maximumSize(1000)</span><br><span class="line">                .expireAfterWrite(10, TimeUnit.SECONDS)</span><br><span class="line">                .refreshAfterWrite(5, TimeUnit.SECONDS)</span><br><span class="line">                .build(new CacheLoader&lt;String, Student&gt;() &#123;</span><br><span class="line">                    @Override</span><br><span class="line">                    public Student load(String key) throws Exception &#123;</span><br><span class="line">                        Student student = Student.builder()</span><br><span class="line">                                .id(10001)</span><br><span class="line">                                .name(&quot;guava loading cache&quot;)</span><br><span class="line">                                .build();</span><br><span class="line">                        System.out.println(&quot;【加载数据并放入缓存，缓存key】:&quot; + key);</span><br><span class="line">                        return student;</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        while (true) &#123;</span><br><span class="line">            System.out.println(loadingCache.get(&quot;student-loading-cache&quot;));</span><br><span class="line">            Thread.sleep(1000);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>效果如下：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">【加载数据并放入缓存，缓存key】:student-loading-cache</span><br><span class="line">Student(id=10001, name=guava loading cache)</span><br><span class="line">Student(id=10001, name=guava loading cache)</span><br><span class="line">Student(id=10001, name=guava loading cache)</span><br><span class="line">Student(id=10001, name=guava loading cache)</span><br><span class="line">Student(id=10001, name=guava loading cache)</span><br><span class="line">【加载数据并放入缓存，缓存key】:student-loading-cache</span><br><span class="line">Student(id=10001, name=guava loading cache)</span><br><span class="line">Student(id=10001, name=guava loading cache)</span><br><span class="line">Student(id=10001, name=guava loading cache)</span><br><span class="line">Student(id=10001, name=guava loading cache)</span><br><span class="line">Student(id=10001, name=guava loading cache)</span><br><span class="line">【加载数据并放入缓存，缓存key】:student-loading-cache</span><br><span class="line">Student(id=10001, name=guava loading cache)</span><br><span class="line">Student(id=10001, name=guava loading cache)</span><br><span class="line">Student(id=10001, name=guava loading cache)</span><br><span class="line">Student(id=10001, name=guava loading cache)</span><br></pre></td></tr></table></figure></p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Guava/" rel="tag"># Guava</a>
          
            <a href="/tags/缓存/" rel="tag"># 缓存</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/12/04/Spring-Boot集成Sentry错误追踪/Spring-Boot集成Sentry错误追踪/" rel="next" title="Spring Boot集成Sentry错误追踪">
                <i class="fa fa-chevron-left"></i> Spring Boot集成Sentry错误追踪
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018/12/06/Hystrix原理/Hystrix原理/" rel="prev" title="Hystrix原理">
                Hystrix原理 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">Wolf、Heart</p>
              <p class="site-description motion-element" itemprop="description">主要用于分享平时学习的只是以及遇到的困难，帮助自己以及需要的人一起共同成长</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">45</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">14</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">13</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#使用Guava库来实现JVM缓存，通过2种不同的方式实现，并测试提供的缓存失效、缓存定时刷新、缓存删除监听功能"><span class="nav-number">1.</span> <span class="nav-text">使用Guava库来实现JVM缓存，通过2种不同的方式实现，并测试提供的缓存失效、缓存定时刷新、缓存删除监听功能</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#方式一：LoadingCache"><span class="nav-number"></span> <span class="nav-text">方式一：LoadingCache</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#方式二：LocalManualCache"><span class="nav-number"></span> <span class="nav-text">方式二：LocalManualCache</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#方式三：测试maximumSize含义"><span class="nav-number"></span> <span class="nav-text">方式三：测试maximumSize含义</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#方式四：刷新缓存"><span class="nav-number"></span> <span class="nav-text">方式四：刷新缓存</span></a></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Wolf、Heart</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
